from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-08 14:12:53.372256
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 08, Sep, 2021
Time: 14:12:58
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.0709
Nobs: 408.000 HQIC: -46.6056
Log likelihood: 4458.63 FPE: 4.04965e-21
AIC: -46.9557 Det(Omega_mle): 3.25666e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.428828 0.093644 4.579 0.000
L1.Burgenland 0.103956 0.048394 2.148 0.032
L1.Kärnten -0.114004 0.024082 -4.734 0.000
L1.Niederösterreich 0.177370 0.104427 1.699 0.089
L1.Oberösterreich 0.125850 0.101780 1.236 0.216
L1.Salzburg 0.282867 0.050712 5.578 0.000
L1.Steiermark 0.019887 0.067228 0.296 0.767
L1.Tirol 0.107815 0.053142 2.029 0.042
L1.Vorarlberg -0.112804 0.047859 -2.357 0.018
L1.Wien -0.012177 0.092702 -0.131 0.895
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.013105 0.217197 0.060 0.952
L1.Burgenland -0.046294 0.112244 -0.412 0.680
L1.Kärnten 0.037417 0.055855 0.670 0.503
L1.Niederösterreich -0.209821 0.242207 -0.866 0.386
L1.Oberösterreich 0.489264 0.236068 2.073 0.038
L1.Salzburg 0.304478 0.117620 2.589 0.010
L1.Steiermark 0.112562 0.155928 0.722 0.470
L1.Tirol 0.315109 0.123256 2.557 0.011
L1.Vorarlberg 0.000204 0.111005 0.002 0.999
L1.Wien -0.004334 0.215011 -0.020 0.984
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.253632 0.047570 5.332 0.000
L1.Burgenland 0.089763 0.024584 3.651 0.000
L1.Kärnten -0.001152 0.012233 -0.094 0.925
L1.Niederösterreich 0.204608 0.053048 3.857 0.000
L1.Oberösterreich 0.167173 0.051703 3.233 0.001
L1.Salzburg 0.034775 0.025761 1.350 0.177
L1.Steiermark 0.020778 0.034151 0.608 0.543
L1.Tirol 0.064128 0.026995 2.376 0.018
L1.Vorarlberg 0.059503 0.024312 2.447 0.014
L1.Wien 0.108229 0.047091 2.298 0.022
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.179718 0.046657 3.852 0.000
L1.Burgenland 0.048019 0.024112 1.992 0.046
L1.Kärnten -0.006526 0.011998 -0.544 0.587
L1.Niederösterreich 0.139817 0.052030 2.687 0.007
L1.Oberösterreich 0.316704 0.050711 6.245 0.000
L1.Salzburg 0.100111 0.025267 3.962 0.000
L1.Steiermark 0.132369 0.033496 3.952 0.000
L1.Tirol 0.074946 0.026477 2.831 0.005
L1.Vorarlberg 0.055966 0.023845 2.347 0.019
L1.Wien -0.041365 0.046188 -0.896 0.370
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.207270 0.092743 2.235 0.025
L1.Burgenland -0.056695 0.047928 -1.183 0.237
L1.Kärnten -0.034294 0.023850 -1.438 0.150
L1.Niederösterreich 0.123860 0.103422 1.198 0.231
L1.Oberösterreich 0.168219 0.100801 1.669 0.095
L1.Salzburg 0.258203 0.050224 5.141 0.000
L1.Steiermark 0.077861 0.066581 1.169 0.242
L1.Tirol 0.121897 0.052630 2.316 0.021
L1.Vorarlberg 0.115514 0.047399 2.437 0.015
L1.Wien 0.022607 0.091809 0.246 0.805
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.026529 0.071981 0.369 0.712
L1.Burgenland 0.024358 0.037199 0.655 0.513
L1.Kärnten 0.052230 0.018511 2.822 0.005
L1.Niederösterreich 0.214985 0.080270 2.678 0.007
L1.Oberösterreich 0.335233 0.078235 4.285 0.000
L1.Salzburg 0.045479 0.038980 1.167 0.243
L1.Steiermark -0.005230 0.051676 -0.101 0.919
L1.Tirol 0.112969 0.040848 2.766 0.006
L1.Vorarlberg 0.065535 0.036788 1.781 0.075
L1.Wien 0.128763 0.071257 1.807 0.071
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185825 0.087920 2.114 0.035
L1.Burgenland 0.020490 0.045436 0.451 0.652
L1.Kärnten -0.058206 0.022609 -2.574 0.010
L1.Niederösterreich -0.114264 0.098043 -1.165 0.244
L1.Oberösterreich 0.190065 0.095559 1.989 0.047
L1.Salzburg 0.028472 0.047612 0.598 0.550
L1.Steiermark 0.299875 0.063119 4.751 0.000
L1.Tirol 0.489593 0.049893 9.813 0.000
L1.Vorarlberg 0.069263 0.044934 1.541 0.123
L1.Wien -0.108092 0.087035 -1.242 0.214
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158007 0.095624 1.652 0.098
L1.Burgenland -0.007275 0.049417 -0.147 0.883
L1.Kärnten 0.062368 0.024591 2.536 0.011
L1.Niederösterreich 0.194744 0.106635 1.826 0.068
L1.Oberösterreich -0.125226 0.103933 -1.205 0.228
L1.Salzburg 0.237945 0.051784 4.595 0.000
L1.Steiermark 0.156464 0.068650 2.279 0.023
L1.Tirol 0.049804 0.054265 0.918 0.359
L1.Vorarlberg 0.125510 0.048872 2.568 0.010
L1.Wien 0.150364 0.094662 1.588 0.112
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.489383 0.051851 9.438 0.000
L1.Burgenland -0.010157 0.026796 -0.379 0.705
L1.Kärnten -0.009851 0.013334 -0.739 0.460
L1.Niederösterreich 0.203226 0.057822 3.515 0.000
L1.Oberösterreich 0.258801 0.056356 4.592 0.000
L1.Salzburg 0.023690 0.028079 0.844 0.399
L1.Steiermark -0.024983 0.037224 -0.671 0.502
L1.Tirol 0.068583 0.029425 2.331 0.020
L1.Vorarlberg 0.058881 0.026500 2.222 0.026
L1.Wien -0.054561 0.051329 -1.063 0.288
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.020200 0.080977 0.137720 0.135187 0.040381 0.071119 -0.001632 0.174835
Kärnten 0.020200 1.000000 -0.045788 0.126755 0.047145 0.069888 0.456429 -0.094424 0.092907
Niederösterreich 0.080977 -0.045788 1.000000 0.284727 0.081447 0.270881 0.027861 0.142523 0.258522
Oberösterreich 0.137720 0.126755 0.284727 1.000000 0.182117 0.285743 0.157596 0.102984 0.140173
Salzburg 0.135187 0.047145 0.081447 0.182117 1.000000 0.126777 0.058054 0.101916 0.050580
Steiermark 0.040381 0.069888 0.270881 0.285743 0.126777 1.000000 0.130345 0.087614 -0.024857
Tirol 0.071119 0.456429 0.027861 0.157596 0.058054 0.130345 1.000000 0.040126 0.116530
Vorarlberg -0.001632 -0.094424 0.142523 0.102984 0.101916 0.087614 0.040126 1.000000 -0.047579
Wien 0.174835 0.092907 0.258522 0.140173 0.050580 -0.024857 0.116530 -0.047579 1.000000